<?php

/**
 * componenttype actions.
 *
 * @package    student_manager
 * @subpackage componenttype
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 2288 2006-10-02 15:22:13Z fabien $
 */
class componenttypeActions extends autocomponenttypeActions
{
    
  public function executeList()
  {
    $this->getResponse()->setTitle('WMS-Component-Type-List');
    $this->processSort();

    $this->processFilters();


    // pager
    $this->pager = new sfPropelPager('ComponentType', 25);
    $c = new Criteria();
    $c->addDescendingOrderByColumn(ComponentTypePeer::ID );
    
    $this->addSortCriteria($c);
    $this->addFiltersCriteria($c);
    $this->pager->setCriteria($c);
    $this->pager->setPage($this->getRequestParameter('page', $this->getUser()->getAttribute('page', 1, 'sf_admin/component_type')));
    $this->pager->init();
    // save page
    if ($this->getRequestParameter('page')) {
        $this->getUser()->setAttribute('page', $this->getRequestParameter('page'), 'sf_admin/component_type');
    }
  }
  public function executeDelete()
  {
    $this->component_type = ComponentTypePeer::retrieveByPk($this->getRequestParameter('id'));
    $this->forward404Unless($this->component_type);

    if (!$this->getUser()->hasGroup('Administrator') ){
        $this->getRequest()->setError('delete', 'Could not delete this Item');
        return $this->forward('componenttype', 'list');
    }

    try
    {
      $this->deleteComponentType($this->component_type);
    }
    catch (PropelException $e)
    {
      $this->getRequest()->setError('delete', 'Could not delete the selected Component type. Make sure it does not have any associated items.');
      return $this->forward('componenttype', 'list');
    }

    return $this->redirect('componenttype/list');
  }
}
